package com.shopping.huaju.commodity.web.controller;

import com.shopping.huaju.commodity.entity.CategoryEntity;
import com.shopping.huaju.commodity.entity.vo.Catalog2VO;
import com.shopping.huaju.commodity.service.CategoryService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
public class IndexController {
    @Resource
    private CategoryService categoryService;
    @GetMapping(value = {"/","index.html"})
    private String indexPage(Model model) {
        //默认找的是 "classpath\templates\"+"index"+".html"
        List<CategoryEntity> category1 = categoryService.getLevel1Categories();
        model.addAttribute("categories",category1);
        return "index";
    }
    @GetMapping("/index/catalog.json")
    @ResponseBody
    private Map<String,List<Catalog2VO>> getCatalogLevelMap(){
        return categoryService.getCatalogLevelMap();
    }
}
